-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prepare timit manifests #324
Conversation
lhotse/recipes/timit.py
Outdated
|
||
def download_and_unzip( | ||
target_dir: Pathlike = '.', | ||
force_download: Optional[bool] = False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are force_download
and base_url
Optional
?
What if Optional
is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the timit zip exits, we needn't to download. Optional in here means that we can download or not download. And the base_url is not unique.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional
here means you can pass None
to the argument. Obviously, base_url
cannot be None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the types should be plain bool and str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
force_download: Optional[bool] = False, | |
force_download: bool = False, |
lhotse/recipes/timit.py
Outdated
force_download: Optional[bool] = False, | ||
base_url: Optional[str] = 'https://data.deepai.org/timit.zip') -> None: | ||
""" | ||
Download and unzip the dataset, supporting both TIMIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does supporting both TIMIT
mean? Is there something missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Em, yes, I am rewriting.
output_dir: Optional[Pathlike] = None, | ||
num_jobs: int = 1 | ||
) -> Dict[str, Dict[str, Union[RecordingSet, SupervisionSet]]]: | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will do it.
lhotse/recipes/timit.py
Outdated
assert corpus_dir.is_dir(), f'No such directory: {corpus_dir}' | ||
|
||
splits_dir = Path(splits_dir) | ||
assert corpus_dir.is_dir(), f'No such directory: {splits_dir}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert corpus_dir.is_dir(), f'No such directory: {splits_dir}' | |
assert splits_dir.is_dir(), f'No such directory: {splits_dir}' |
lhotse/recipes/timit.py
Outdated
from collections import defaultdict | ||
|
||
import os | ||
import glob |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove packages that are not used.
lhotse/recipes/timit.py
Outdated
|
||
with ThreadPoolExecutor(num_jobs) as ex: | ||
for part in dataset_parts: | ||
wav_files = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wav_files = [] |
lhotse/recipes/timit.py
Outdated
with ThreadPoolExecutor(num_jobs) as ex: | ||
for part in dataset_parts: | ||
wav_files = [] | ||
file_name = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file_name = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left some comments. Can you also update the table in docs/corpus.rst and add a CLI mode for TIMIT (see lhotse/bin/modes/recipes for a lot of examples)
lhotse/recipes/timit.py
Outdated
from lhotse.utils import Pathlike, urlretrieve_progress | ||
|
||
|
||
def download_and_unzip( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to name it “download_timit”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!
lhotse/recipes/timit.py
Outdated
|
||
def download_and_unzip( | ||
target_dir: Pathlike = '.', | ||
force_download: Optional[bool] = False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the types should be plain bool and str
lhotse/recipes/timit.py
Outdated
file_name = '' | ||
|
||
if part == 'TRAIN': | ||
file_name = os.path.join(splits_dir, 'train_samples.txt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace all os.path.join(a, b) with: a / b (this is possible because we use Path objects)
lhotse/recipes/timit.py
Outdated
items = wav_file.split('/') | ||
idx = items[-2] + '-' + items[-1][:-4] | ||
speaker = items[-2] | ||
transcript_file = wav_file[:-3] + 'PHN' ###the phone file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wav_file.with_suffix(‘.PHN’)
output_dir = Path(output_dir) | ||
output_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
manifests = defaultdict(dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does a plain dict
work here?
Any reason to use a defaultdict
?
lhotse/recipes/timit.py
Outdated
wav_files = [] | ||
with open(file_name, 'r') as f: | ||
lines = f.readlines() | ||
for line in lines: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for line in f
No need to read all lines at once.
@@ -98,8 +98,8 @@ def prepare_timit( | |||
for wav_file in tqdm(wav_files): | |||
items = wav_file.split('/') | |||
idx = items[-2] + '-' + items[-1][:-4] | |||
speaker = items[-2] | |||
transcript_file = wav_file[:-3] + 'PHN' ###the phone file | |||
speaker = items[-2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove ALL leading and trailing spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do it.
lhotse/recipes/timit.py
Outdated
""" | ||
target_dir = Path(target_dir) | ||
target_dir.mkdir(parents=True, exist_ok=True) | ||
tar_name = f'timit.zip' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe f-string is not necessarily needed here.
- tar_name = f'timit.zip'
+ tar_name = 'timit.zip'
lhotse/recipes/timit.py
Outdated
file_name = '' | ||
|
||
if part == 'TRAIN': | ||
file_name = splits_dir/'train_samples.txt' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to add a space before and after opterator "/".
-file_name = splits_dir/'train_samples.txt'
+ file_name = splits_dir / 'train_samples.txt'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Sometimes TIMIT has logic for using a 48-phone version or some other size of phone set. |
just IMO, yes...
y.
…On Wed, Jun 30, 2021 at 3:49 PM Daniel Povey ***@***.***> wrote:
Sometimes TIMIT has logic for using a 48-phone version or some other size
of phone set.
Does it make sense to include that logic here?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#324 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUKYX7DU2N7SSQ4QMIDSL3TVMOH7ANCNFSM47PCSD6A>
.
|
Let me know when it is ready to merge |
Yes,here, maybe I should add three options(60, 48, 39) for choosing the number of phonemes. The attach phones_60_48_39.txt is the same as the phones.60-48-39.map in kaldi. |
I will set 48-phone version as the default. |
@pzelasko , I add the function which can convert the phones to 48 (default) or 39. And I think it is ready to merge. |
corpus_dir: Pathlike, | ||
splits_dir: Pathlike, | ||
output_dir: Optional[Pathlike] = None, | ||
num_phones: int = 48, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some documentation about the possible options for num_phones
.
|
||
return manifests | ||
|
||
def get_phonemes(num_phones): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this function also handle 60 phones?
Also please raise an exception if somebody passes a different number than 39 / 48 (and maybe 60 if it makes sense).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve my two last comments and I'm OK to merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve my two last comments and I'm OK to merge it.
Thanks for your advice! Done it.
lhotse/recipes/timit.py
Outdated
from lhotse.utils import Pathlike, urlretrieve_progress | ||
|
||
|
||
def download_and_unzip( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!
@@ -98,8 +98,8 @@ def prepare_timit( | |||
for wav_file in tqdm(wav_files): | |||
items = wav_file.split('/') | |||
idx = items[-2] + '-' + items[-1][:-4] | |||
speaker = items[-2] | |||
transcript_file = wav_file[:-3] + 'PHN' ###the phone file | |||
speaker = items[-2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do it.
|
lhotse/recipes/timit.py
Outdated
|
||
phones_dict = get_phonemes(num_phones) | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to use try .. except here?
What happens if it is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Em....it is to remind people to set num_phones in [60, 48, 39]. If the value of num_phones not in [60, 48, 39], the error happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @csukuangfj that this try/except block is unnecessary. Please change:
try:
if num_phones in [60, 48, 39]:
phones_dict = get_phonemes(num_phones)
else:
raise ValueError("The value of num_phones must be in [60, 48, 39].")
except ValueError as e:
print("Exception: ", repr(e))
raise
into
if num_phones in [60, 48, 39]:
phones_dict = get_phonemes(num_phones)
else:
raise ValueError("The value of num_phones must be in [60, 48, 39].")
lhotse/recipes/timit.py
Outdated
import os | ||
import zipfile | ||
import logging | ||
import string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import string |
lhotse/recipes/timit.py
Outdated
|
||
def download_and_unzip( | ||
target_dir: Pathlike = '.', | ||
force_download: Optional[bool] = False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
force_download: Optional[bool] = False, | |
force_download: bool = False, |
lhotse/recipes/timit.py
Outdated
base_url: Optional[str] = 'https://data.deepai.org/timit.zip') -> None: | ||
""" | ||
Download and unzip the dataset TIMIT. | ||
:param target_dir: Pathlike, the path of the dir to storage the dataset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param target_dir: Pathlike, the path of the dir to storage the dataset. | |
:param target_dir: Pathlike, the path of the dir to store the dataset. |
lhotse/recipes/timit.py
Outdated
""" | ||
Download and unzip the dataset TIMIT. | ||
:param target_dir: Pathlike, the path of the dir to storage the dataset. | ||
:param force_download: Bool, if True, download the zips no matter if the zips exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param force_download: Bool, if True, download the zips no matter if the zips exists. | |
:param force_download: bool, if True, download the zips no matter if the zips exists. |
lhotse/recipes/timit.py
Outdated
Download and unzip the dataset TIMIT. | ||
:param target_dir: Pathlike, the path of the dir to storage the dataset. | ||
:param force_download: Bool, if True, download the zips no matter if the zips exists. | ||
:param base_url: str, the url of the TIMIT download for free. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param base_url: str, the url of the TIMIT download for free. | |
:param base_url: str, the URL of the TIMIT dataset to download. |
lhotse/recipes/timit.py
Outdated
lines = f.readlines() | ||
for line in lines: | ||
items = line.strip().split(' ') | ||
wav = os.path.join(corpus_dir, items[-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wav = os.path.join(corpus_dir, items[-1]) | |
wav = corpus_dir / items[-1] |
lhotse/recipes/timit.py
Outdated
items = line.strip().split(' ') | ||
wav = os.path.join(corpus_dir, items[-1]) | ||
wav_files.append(wav) | ||
print(f'{part} dataset manifest generation.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(f'{part} dataset manifest generation.') | |
logging.debug(f'{part} dataset manifest generation.') |
|
||
return manifests | ||
|
||
def get_phonemes(num_phones): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document this function.
lhotse/recipes/timit.py
Outdated
phonemes["zh"] = "sh" | ||
|
||
else: | ||
print("Using 60 phones for modeling!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be consistent: You're using both logging
and print
. Please choose either one, not both.
@csukuangfj and @pzelasko , thanks for your advice! Done it. |
Cool, thank you @luomingshuang! I am merging, if any issues come up later we can do a follow up PR. |
Good!
…---Original---
From: "Piotr ***@***.***>
Date: Mon, Jul 19, 2021 10:15 AM
To: ***@***.***>;
Cc: "Mingshuang ***@***.******@***.***>;
Subject: Re: [lhotse-speech/lhotse] prepare timit manifests (#324)
Cool, thank you @luomingshuang! I am merging, if any issues come up later we can do a follow up PR.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
In timit.py, I use phonemes as the supervisions.